package com.stockz.watchlist.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.stockz.equity.model.Scrip;

@Entity
@IdClass(EntryPrimaryKey.class)
public class Entry implements Serializable {
	private static final long serialVersionUID = -4753339049026267284L;

	private WatchList watchList;
	private Scrip scrip;
	private String description;
	private Date createDate;
	
	@Override
	public String toString() {
		return scrip+" : "+description+" : "+createDate+watchList;
	}
	
	@Id
	@ManyToOne  
	@JoinColumn(name="watchlistid")        
	public WatchList getWatchList() {
		return watchList;
	}
	public void setWatchList(WatchList watchList) {
		this.watchList = watchList;
	}
	@Id
	@ManyToOne  
	@JoinColumn(name="scripcode")        
	public Scrip getScrip() {
		return scrip;
	}
	public void setScrip(Scrip scrip) {
		this.scrip = scrip;
	}
	@Column
	@Lob
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	@Column(insertable=true,updatable=false)
	@Temporal(TemporalType.DATE)
	public Date getCreateDate() {
		return createDate;
	}
	
	@PrePersist
	private void prePersist(){
		this.createDate = new Date();
	}
	
	private void setCreateDate(Date createDate) {
		this.createDate = new Date();
	}
	
}